<template>
	<view class="tabbar-container">
		<block>
			<view class="tabbar-item" v-for="(item, index) in tabbarList"
				:class="[item.centerItem ? 'center-item' : item.classType]"
				:style="{width:tabbarList.length==4 ?'25%':'20%'}" @click="changeItem(item)">
				<view class="item-top">
					<image :src="currentItem == item.id ? item.selectIcon : item.icon"></image>
					
					<!-- <image src="../../../../static/img/notice.png"></image> -->
				</view>
				<view class="item-bottom" :class="[currentItem == item.id ? 'item-active' : '']">
					<text>{{ item.text }}</text>
				</view>
			</view>
		</block>
		<uni-popup class="homePage-bottom-popup" ref="popup" background-color="none" @change="change">
			<view class="homePage-bottom-popup-content">
				弹出自定义的菜单
				<!-- <view class="flex-alignc-justify-between popup-btn">
					<view class="popup-btn-left" @click="newBuildProject">
						<image style="width: 80rpx;height: 80rpx;" :src="`${STORAGE_STATIC}` + '/new_project.png'"
							mode=""></image>
						<view style="padding-top: 20rpx;color: #595959;">新建工程</view>
					</view>
					<view class="popup-btn-right" @click="addEquipment">
						<image style="width: 100rpx;height: 100rpx;" :src="`${STORAGE_STATIC}` + '/add_eq.png'" mode="">
						</image>
						<view class="" style="color: #595959;">添加设备</view>
					</view>
				</view> -->
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		props: {
			currentPage: {
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				currentItem: 0,
				addVisible: false,
				tabbarList: [{
					id: 0,
					path: '/pages/test/test',
					icon: '../../static/img/home.png',
					selectIcon: '../../static/img/home_select.png',
					text: '界面1',
					classType: 'tabbar-home-item',
					centerItem: false
				}, {
					id: 1,
					path: '/pages/test2/test2',
					icon: '../../static/img/monitor.png',
					selectIcon: '../../static/img/monitor_select.png',
					text: '界面2',
					classType: 'tabbar-monitor-item',
					centerItem: false
				}, {
					id: 2,
					path: '/pages/add/add',
					icon: '../../static/img/add.png',
					selectIcon: '../../static/img/add.png',
					text: '',
					centerItem: true
				}, {
					id: 3,
					path: '/pages/test4/test4',
					icon: '../../static/img/notice.png',
					selectIcon: '../../static/img/notice_select.png',
					text: '界面4',
					classType: 'tabbar-notice-item',
					centerItem: false
				}, {
					id: 4,
					path: '/pages/test5/test5',
					icon: '../../static/img/me.png',
					selectIcon: '../../static/img/me_select.png',
					text: '界面5',
					classType: 'tabbar-me-item',
					centerItem: false
				}, ]
			}
		},
		mounted() {
			this.currentItem = this.currentPage;
			uni.hideTabBar();

		},
		methods: {
			changeItem(item) {
				let _this = this;

				//_this.currentItem = item.id;

				if (item.id === 2) {

					//todo 跳转到自己需要的界面
					// uni.navigateTo({
					// 	url: '../../pages/addEquipment/addEquipment'
					// })
					this.$refs.popup.open('bottom')
					return
				}
				this.$refs.popup.close('bottom')
				uni.switchTab({
					url: item.path
				});
			},
			change(e) {
				// console.log('popup- c', e)
			},
			newBuildProject() {

				this.$refs.popup.close()
				//todo 跳转到自己需要的界面
				// uni.navigateTo({
				// 	url: '../../pages/newProject/newProject'
				// })
			},
			addEquipment() {
				this.$refs.popup.close()
				//todo 跳转到自己需要的界面
				// uni.navigateTo({
				// 	url: '../../pages/addEquipment/addEquipment'
				// })
			},
		}
	}
</script>

<style lang="scss" scoped>
	view {
		padding: 0;
		margin: 0;
		box-sizing: border-box;
	}

	.tabbar-container {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 100rpx;
		box-shadow: 0 0 5px #D7D7D7;
		display: flex;
		align-items: center;
		padding: 5rpx 0;
		color: #D7D7D7;
		z-index: 10;
		background: #fff;
	}

	.tabbar-container .tabbar-item {
		width: 20%;
		height: 100rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		text-align: center;

		.item-top image {
			width: 100%;
			height: 100%;
		}
	}

	.tabbar-container .item-active {
		color: #749ff4;
	}

	.tabbar-container .center-item {
		display: block;
		position: relative;
		// opacity: 0.9;
	}

	// .tabbar-container .tabbar-item .item-top {
	// 	width: 70rpx;
	// 	height: 70rpx;
	// 	padding: 10rpx;
	// }

	.tabbar-container .tabbar-add-item {
		// opacity: 0.5!important;
	}

	.tabbar-container .tabbar-home-item .item-top {
		width: 60rpx;
		height: 60rpx;
		padding: 10rpx;
	}

	.tabbar-container .tabbar-monitor-item .item-top {
		width: 60rpx;
		height: 60rpx;
		padding: 10rpx;
	}

	.tabbar-container .tabbar-notice-item .item-top {
		width: 60rpx;
		height: 60rpx;
		padding: 10rpx;
	}

	.tabbar-container .tabbar-me-item .item-top {
		width: 60rpx;
		height: 60rpx;
		padding: 10rpx;
	}

	.tabbar-container .center-item .item-top {
		flex-shrink: 0;
		width: 100rpx;
		height: 100rpx;
		position: absolute;
		top: -50rpx;
		left: calc(50% - 50rpx);
		border-radius: 50%;
		box-shadow: 0 0 5px #D7D7D7;
		background-color: #ffffff;
	}

	.tabbar-container .tabbar-item .item-top image {
		width: 100%;
		height: 100%;
	}

	.tabbar-container .tabbar-item .item-bottom {
		font-size: 28rpx;
		width: 100%;
	}

	.tabbar-container .center-item .item-bottom {
		position: absolute;
		bottom: 5rpx;
	}

	.homePage-bottom {
		// position: fixed;
		// bottom: 0;
		// width: calc(100vw - 40rpx);
		// z-index: 10;
		position: absolute;
		left: 50%;
		bottom: 50rpx;
		transform: translateX(-50%);
		z-index: -1;

		&-popup {
			z-index: -1;

			&-content {
				min-height: 340rpx;
				border-top-left-radius: 50rpx;
				border-top-right-radius: 50rpx;
				background-color: #fff;
				padding: 0 60rpx 70rpx 60rpx;

				.popup-btn {
					margin: 30rpx auto;
					padding-top: 30rpx;

					.popup-btn-left {
						width: 230rpx;
						text-align: center;
					}

					.popup-btn-right {
						width: 230rpx;
						text-align: center;
					}
				}
			}
		}
	}
</style>